<?php

namespace App\Http\Controllers\v1;

use App\Models\User;
use Illuminate\Http\Request;
use Illuminate\Http\Exception\HttpResponseException;
use JWTAuth;
use Tymon\JWTAuth\Exceptions\JWTException;
use Illuminate\Http\Response as IlluminateResponse;
use JWTFactory;
use App\Http\Controllers\Controller;

class AuthController extends Controller {
	/**
	 * Create a new controller instance.
	 *
	 * @return void
	 */
	protected $app;
	
	/**
	 *
	 * @param \Laravel\Lumen\Application $app        	
	 */
	public function __construct(\Laravel\Lumen\Application $app) {
		$this->app = $app;
	}
	
	/**
	 * 退出
	 *
	 * @param Request $request        	
	 */
	public function loginout(Request $request) {
		$token = JWTAuth::getToken ();
		JWTAuth::invalidate ( $token );
		
		return responseError ();
	}
	
	/**
	 * 已登录的用户利用openid获取token
	 *
	 * @param Request $request        	
	 */
	public function token(Request $request) {
		$token = JWTAuth::attempt ();
		
		return responseData ( $token );
	}
	
	/**
	 * 刷新token
	 *
	 * @param Request $request        	
	 * @return unknown
	 */
	public function refresh(Request $request) {
		$old_token = JWTAuth::getToken ();
		$token = JWTAuth::refresh ( $old_token );
		
		return responseData ( $token );
	}
	
	/**
	 * 使token失效
	 *
	 * @param Request $request        	
	 */
	public function invalidate(Request $request) {
		$token = JWTAuth::getToken ();
		JWTAuth::invalidate ( $token );
		
		return responseError ();
	}
	
	/**
	 * 验证token
	 */
	public function vertify() {
		return responseError ();
	}
}
